package com.ly.ThreadExit;

public class ThreadMethod04 {
    public static void main(String[] args) throws InterruptedException {
        Thread t3 = new Thread(new T3());
        for (int i = 1; i <= 10; i++) {
            Thread.sleep(1000);
            System.out.println("hi"+i);
            if (i==5){//说明主线程输了5次
                t3.start();//输出hello
                t3.join();//加入主线程，子线程执行完毕后，主线程才继续执行
            }
        }

    }
}
class T3 implements Runnable{

    @Override
    public void run() {
        int count = 0;
        while (true) {
            System.out.println("hello"+(++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (count==10){
                break;
            }
        }
    }
}
